/*
 * @Author: yangzonglong
 * @Date: 2021-05-13 16:57:27
 * @version: v1.0.0
 * @Descripttion: bpmn辅助方法
 * @LastEditors: yangzonglong
 * @LastEditTime: 2023-02-16 20:36:57
 * @Auditor: 
 */

import { UserTaskSelfProps } from './../interface';

export const BPMN_NODE_TYPE = {
  'EXTENSION_ELEMENTS': 'bpmn:ExtensionElements',
  'START_EVENT': 'bpmn:StartEvent',
  'USER_TASK': 'bpmn:UserTask',
  'PARALLEL_GATEWAY': 'bpmn:ParallelGateway', // 并行网关
  'EXCLUSIVE_GATEWAY': 'bpmn:ExclusiveGateway',
  "SEQUENCE_FLOW": "bpmn:SequenceFlow",
  'HL_ANDGATE_CONDITION_VAR': 'huilian:ANDGateConditionVar', // 条件设置 与
  'HL_ORGATE_CONDITION_VAR': 'huilian:ORGateConditionVar', // 条件设置 或
  'HL_CONDITION': 'huilian:Condition', // 条件设置 子节点
  'FORMAL_EXPRESSION': 'bpmn:FormalExpression', // 自定义 脚本设置
  'HL_INVISIBLE_LIST': 'huilian:InvisibleList', // 隐藏参数父节点
  'HL_VARIABLE': 'huilian:Variable', // 隐藏参数子节点
  'HL_ACTION': 'huilian:Action',
  'HL_ACTION_DATA': 'huilian:ActionData', // action 节点
  'HL_EDITABLE_NODE': 'huilian:EditableNode', // 可编辑参数父节点
  'HL_EDITTABLE_NODE_CHILD': 'huilian:Node', // 可编辑参数子节点
  'HL_PAGE_SET': 'huilian:PageSetting', // 页面设置
  'HL_ATTACHMENT': 'huilian:Attachment', // 页面附件设置
  'HL_USER_LIST': 'huilian:UserList', // 通知节点 用户LIST
  'HL_USER': 'huilian:User', // 通知节点 用户
  'HL_CC_USER_LIST': 'huilian:CcUserList', // 抄送
  'HL_BCC_USER_LIST': 'huilian:BccUserList', // 密送
}

export function createBpmnXMLNode(modeler: any, nodeType: string) {
  return modeler.get('moddle').create(nodeType)
}

export function updateUserTask(modeler: any, self: UserTaskSelfProps, index: number, data: any) {
  self.businessObject!.extensionElements = Object.assign(createBpmnXMLNode(modeler, BPMN_NODE_TYPE.EXTENSION_ELEMENTS), {
    values: [
      self.businessObject?.extensionElements?.values?.[0] || createBpmnXMLNode(modeler,BPMN_NODE_TYPE.HL_ACTION_DATA),
      self.businessObject?.extensionElements?.values?.[1] || createBpmnXMLNode(modeler, BPMN_NODE_TYPE.HL_INVISIBLE_LIST),
      self.businessObject?.extensionElements?.values?.[2] || createBpmnXMLNode(modeler, BPMN_NODE_TYPE.HL_EDITABLE_NODE),
      self.businessObject?.extensionElements?.values?.[3] ||createBpmnXMLNode(modeler, BPMN_NODE_TYPE.HL_PAGE_SET)
    ]
  })
  self.businessObject!.extensionElements!.values![index] = data;
}